package org.jmc.refmanager.web.wicket.page.error;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.jmc.refmanager.util.HttpUtils;
import org.jmc.refmanager.web.wicket.page.HomePage;

/**
 * Base class for custom error pages.
 */
public abstract class BaseErrorPage extends WebPage {
	/**
	 * Error pages are not bookmarkable, hence no PageParameters.
	 */
	protected BaseErrorPage() {
		super();
		add(new BookmarkablePageLink<WebPage>("linkHomePage", HomePage.class));
	}

	/**
	 * Subclasses must implement to provide the HTTP status error code. For
	 * example, 404 for the {@link NotFoundErrorPage}.
	 */
	protected abstract int getErrorCode();

	/**
	 * Make sure we emit the proper HTTP status.
	 */
	@Override
	protected void configureResponse() {
		super.configureResponse();
		HttpUtils.getHttpServletResponse().setStatus(getErrorCode());
	}

	/**
	 * Returns {@code true}.
	 */
	@Override
	public boolean isErrorPage() {
		return true;
	}
}
